'use strict'
let serverConfig = require('../config/serverConfig').serverConfig
let ws = require('ws').Server
let playerSessionMgr = require('./playerSessionMgr')

class GateServer {
  constructor() {
    this.server = null
    this.curId = 1
  }

  //创建WS服务器
  createServer() {
    let self = this
    this.server = new ws({
      host: serverConfig.ip,
      port: serverConfig.port
    })
    console.log(`用户-网关服务器启动 ${serverConfig.ip}:${serverConfig.port}`)
    this.server.on('connection', function(socket) {
      //创建会话
      Log('新的连接')
      playerSessionMgr.create(self.curId, socket)
      self.curId += 1
    })
  }

  close(socket) {
    session.close()
  }
}

let gateServer = new GateServer()
gateServer.createServer()

exports.wsServer = gateServer
